package com.oracle.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;


import com.oracle.common.BloomStringProcess;
import com.oracle.common.FileProcess;
import com.oracle.service.BregisterService;
import com.oracle.service.FeignRegisterService;
import com.oracle.service.GregisterService;
import com.oracle.service.imp.BloomFilterService;
import com.oracle.vo.Boy;
import com.oracle.vo.Girl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * @program: CampusMatching
 * @description:
 * @author: zhaolei
 * @create: 2020-07-31 13:38
 **/
@RestController
@RequestMapping("/register")
public class registerhandler  implements FeignRegisterService {

    @Autowired
    BregisterService bregisterService;

    @Autowired
    GregisterService gregisterService;

    @Autowired
    FileProcess fileProcess;

    @Autowired
    BloomFilterService bloomFilterService;

    @Autowired
    BloomStringProcess bloomStringProcess;

      @Override
      @HystrixCommand
      @PostMapping(value = "/boy/3")
      public  void registerBoy(@RequestBody Boy boy){
          bregisterService.insertboy(boy);
          System.out.println("插入成功");
          bloomFilterService.addvalue(bloomStringProcess.process(boy));
      }

    @Override
    @PostMapping(value = "/girl/3")
    public  void registerGirl(@RequestBody Girl girl){
          gregisterService.insertgirl(girl);
          System.out.println("插入成功");
          bloomFilterService.addvalue(bloomStringProcess.process(girl));
    }

    @Override
    @PostMapping("/boy/2")
    public  Boy selectboy(@RequestBody Boy boy){
        List<Boy> list = bregisterService.selectboy(boy);
        return list.get(0);
    }


    @Override
    @PostMapping("/girl/2")
    public  Girl selectgirl(@RequestBody Girl girl){
        List<Girl> list = gregisterService.select(girl);
        return  list.get(0);
    }

    @Override
    @PostMapping("/boy/1")
    public  boolean selectBbloom(@RequestBody Boy boy){
        boolean flg=bloomFilterService.getvalue(bloomStringProcess.process(boy));
        if(flg){
            return  true;
        }else {
            return  false;
        }

    }

    @Override
    @PostMapping("/girl/1")
    public  boolean selectGbloom(@RequestBody Girl girl){
       boolean flg=bloomFilterService.getvalue(bloomStringProcess.process(girl));
       if(flg){
           return  true;
       }else {
           return  false;
       }

    }

}
